﻿/************************************************************************

   Extended Silverlight Toolkit

   Copyright (C) 2010-2012 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://extendedsilverlight.codeplex.com/license

   Please purchase a commercial version of this toolkit if you are using
   it in a commercial product. The commercial versions support the project,
   and also include more features for each control, priority support,
   source code, updates, removed watermark, and a proprietary license.

   Visit http://xceed.com and follow @datagrid on Twitter.

  **********************************************************************/

using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using Xceed.Silverlight.Data.Stats;

namespace Xceed.Silverlight.DataGrid
{
  [StyleTypedProperty( Property = "GroupHeaderStyle", StyleTargetType = typeof( GroupHeaderControl ) )]
  public class DataGridGroupConfiguration : DataGridConfiguration, INotifyPropertyChanged
  {
    internal static DataGridGroupConfiguration DefaultGroupConfiguration = new DataGridGroupConfiguration();

    public DataGridGroupConfiguration()
    {
    }











    #region FixedHeaders Property

    public ObservableCollection<DataTemplate> FixedHeaders
    {
      get
      {
        return m_fixedHeaders;
      }
    }

    private ObservableCollection<DataTemplate> m_fixedHeaders = new ObservableCollection<DataTemplate>();

    #endregion

    #region FixedFooters Property

    public ObservableCollection<DataTemplate> FixedFooters
    {
      get
      {
        return m_fixedFooters;
      }
    }

    private ObservableCollection<DataTemplate> m_fixedFooters = new ObservableCollection<DataTemplate>();

    #endregion

    #region StatFunctions Property

    public StatFunctionCollection StatFunctions
    {
      get
      {
        return m_statFunctions;
      }
    }

    private StatFunctionCollection m_statFunctions = new StatFunctionCollection();

    #endregion StatFunctions Property

    #region AllowGroupNavigation Property

    public static readonly DependencyProperty AllowGroupNavigationProperty = DependencyProperty.Register(
      "AllowGroupNavigation",
      typeof( Nullable<bool> ),
      typeof( DataGridGroupConfiguration ),
      new PropertyMetadata( null, new PropertyChangedCallback( DataGridGroupConfiguration.OnAllowGroupNavigationChanged ) ) );

    public Nullable<bool> AllowGroupNavigation
    {
      get
      {
        return ( Nullable<bool> )this.GetValue( DataGridGroupConfiguration.AllowGroupNavigationProperty );
      }
      set
      {
        this.SetValue( DataGridGroupConfiguration.AllowGroupNavigationProperty, value );
      }
    }

    private static void OnAllowGroupNavigationChanged( DependencyObject sender, DependencyPropertyChangedEventArgs e )
    {
      var dataGridGroupConfiguration = ( DataGridGroupConfiguration )sender;
      dataGridGroupConfiguration.RaisePropertyChanged( DataGridControl.AllowGroupNavigationPropertyName );
    }

    #endregion // AllowGroupNavigation Property

    #region GroupNavigationModes Property

    public static readonly DependencyProperty GroupNavigationModesProperty = DependencyProperty.Register(
      "GroupNavigationModes",
      typeof( GroupNavigationModes? ),
      typeof( DataGridGroupConfiguration ),
      new PropertyMetadata( null, new PropertyChangedCallback( DataGridGroupConfiguration.OnGroupNavigationModesChanged ) ) );

    public GroupNavigationModes? GroupNavigationModes
    {
      get
      {
        return ( GroupNavigationModes? )this.GetValue( DataGridGroupConfiguration.GroupNavigationModesProperty );
      }
      set
      {
        this.SetValue( DataGridGroupConfiguration.GroupNavigationModesProperty, value );
      }
    }

    private static void OnGroupNavigationModesChanged( DependencyObject sender, DependencyPropertyChangedEventArgs e )
    {
      var dataGridGroupConfiguration = ( DataGridGroupConfiguration )sender;
      dataGridGroupConfiguration.RaisePropertyChanged( DataGridControl.GroupNavigationModesPropertyName );
    }

    #endregion // GroupNavigationModes Property

    #region AllowGroupCollapsing Property

    public static readonly DependencyProperty AllowGroupCollapsingProperty = DependencyProperty.Register(
      "AllowGroupCollapsing",
      typeof( bool? ),
      typeof( DataGridGroupConfiguration ),
      new PropertyMetadata( null, new PropertyChangedCallback( DataGridGroupConfiguration.OnAllowGroupCollapsingChanged ) ) );

    public bool? AllowGroupCollapsing
    {
      get
      {
        return ( bool? )this.GetValue( DataGridGroupConfiguration.AllowGroupCollapsingProperty );
      }
      set
      {
        this.SetValue( DataGridGroupConfiguration.AllowGroupCollapsingProperty, value );
      }
    }

    private static void OnAllowGroupCollapsingChanged( DependencyObject sender, DependencyPropertyChangedEventArgs e )
    {
      var dataGridGroupConfiguration = ( DataGridGroupConfiguration )sender;
      dataGridGroupConfiguration.RaisePropertyChanged( DataGridControl.AllowGroupCollapsingPropertyName );
    }

    #endregion // AllowGroupCollapsing Property

    #region GroupValueTemplate Property

    public static readonly DependencyProperty GroupValueTemplateProperty = DependencyProperty.Register(
      "GroupValueTemplate",
      typeof( DataTemplate ),
      typeof( DataGridGroupConfiguration ),
      new PropertyMetadata( null ) );

    public DataTemplate GroupValueTemplate
    {
      get
      {
        return ( DataTemplate )this.GetValue( DataGridGroupConfiguration.GroupValueTemplateProperty );
      }
      set
      {
        this.SetValue( DataGridGroupConfiguration.GroupValueTemplateProperty, value );
      }
    }

    #endregion //GroupValueTemplate Property

    #region GroupHeaderStyle Property

    public static readonly DependencyProperty GroupHeaderStyleProperty = DependencyProperty.Register(
      "GroupHeaderStyle",
      typeof( Style ),
      typeof( DataGridGroupConfiguration ),
      new PropertyMetadata(
        ( Style )null ) );

    public Style GroupHeaderStyle
    {
      get
      {
        return ( Style )this.GetValue( DataGridGroupConfiguration.GroupHeaderStyleProperty );
      }
      set
      {
        this.SetValue( DataGridGroupConfiguration.GroupHeaderStyleProperty, value );
      }
    }

    #endregion

    #region SubLevelIndent Property

    public static readonly DependencyProperty SublevelIndentProperty = DependencyProperty.Register(
      "SublevelIndent",
      typeof( double? ),
      typeof( DataGridGroupConfiguration ),
      new PropertyMetadata( null, null ) );

    public double? SublevelIndent
    {
      get
      {
        return ( double? )this.GetValue( DataGridGroupConfiguration.SublevelIndentProperty );
      }
      set
      {
        this.SetValue( DataGridGroupConfiguration.SublevelIndentProperty, value );
      }
    }

    #endregion //SubLevelIndex Property

    #region INotifyPropertyChanged Members

    public event PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChanged( string name )
    {
      Xceed.Silverlight.DataGrid.Utils.ReflectionHelper.ValidatePublicPropertyName( this, name );

      if( this.PropertyChanged != null )
      {
        this.PropertyChanged( this, new PropertyChangedEventArgs( name ) );
      }
    }

    #endregion
  }
}
